<?php
/**
* @file logout.php
* Copyright (c) Friends Group. All rights reserved.
* $Id$
*
*/

require_once(realpath(dirname(__FILE__)) . '/config.php');
require_once(realpath(dirname(__FILE__)) . '/includes/common/ServiceFactory.php');

Session::start();

$authService = ServiceFactory::get("AuthenticationService");
$userService = ServiceFactory::get("UserService");
$commonService = ServiceFactory::get();

if($authService -> isAuthenticated())
{
    $user = $authService -> getCurrentUser();
    $userService -> setUserOption($user -> getID(), "last-status", $userService -> getUserStatus($user -> getID()) -> getStatusText());
    $userService -> setUserStatus($user -> getID(), $commonService -> getStatusByName("Offline"));
    $authService -> logout($user, "./login.php");
}

Response::redirect("./login.php");

?>